﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Problem2
{
    class figura
    {
        int[][] matrix;
        int id;

        public figura(int id)
        {
            this.id = id;
            switch (id)
            {
                case 1:
                    matrix = new int[2][];
                    matrix[0] = new int[4] { id, id, id, id };
                    matrix[1] = new int[4] { 0, id, 0, 0 };
                    break;

                case 2:
                    matrix = new int[2][];
                    matrix[0] = new int[4] { id, id, id, id };
                    matrix[1] = new int[4] { 0, 0, 0, id };
                    break;
                case 3:
                    matrix = new int[1][];
                    matrix[0] = new int[5] { id, id, id, id, id };
                    break;
                case 4:
                    matrix = new int[2][];
                    matrix[0] = new int[3] { id, id, 0 };
                    matrix[1] = new int[3] { id, id, id };
                    break;
                case 5:
                    matrix = new int[3][];
                    matrix[0] = new int[3] { id, id, id };
                    matrix[1] = new int[3] { 0, id, 0 };
                    matrix[2] = new int[3] { 0, id, 0 };
                    break;

                case 6:
                    matrix = new int[3][];
                    matrix[0] = new int[3] { 0, id, id };
                    matrix[1] = new int[3] { id, id, 0 };
                    matrix[2] = new int[3] { id, 0, 0 };
                    break;
                case 7:
                    matrix = new int[2][];
                    matrix[0] = new int[3] { id, id, id };
                    matrix[1] = new int[3] { id, 0, id };
                    break;
                case 8:
                    matrix = new int[3][];
                    matrix[0] = new int[3] { 0, id, 0 };
                    matrix[1] = new int[3] { id, id, id };
                    matrix[2] = new int[3] { 0, id, 0 };
                    break;
                case 9:
                    matrix = new int[3][];
                    matrix[0] = new int[3] { 0, id, id };
                    matrix[1] = new int[3] { 0, id, 0 };
                    matrix[2] = new int[3] { id, id, 0 };
                    break;

                case 10:
                    matrix = new int[3][];
                    matrix[0] = new int[3] { 0, id, 0 };
                    matrix[1] = new int[3] { id, id, id };
                    matrix[2] = new int[3] { id, 0, 0 };
                    break;
                case 11:
                    matrix = new int[2][];
                    matrix[0] = new int[4] { id, id, 0, 0 };
                    matrix[1] = new int[4] { 0, id, id, id };
                    break;
                case 12:
                    matrix = new int[3][];
                    matrix[0] = new int[3] { id, id, id };
                    matrix[1] = new int[3] { id, 0, 0 };
                    matrix[2] = new int[3] { id, 0, 0 };
                    break;
            }
        }



        public int[][] getMatrix()
        {
            return this.matrix;
        }
        public int getLengthH()
        {
            int length = 0;
            for (int i = 0; i < matrix.Length; i++)
            {
                int localLength = 0;
                for (int j = 0; j < matrix[i].Length; j++)
                {
                    if (matrix[i][j] > 0)
                        localLength = j + 1;
                }
                if (localLength > length)
                    length = localLength;
            }
            return length;
        }

        public int getLengthV()
        {
            int length = 0;
            for (int i = 0; i < matrix.Length; i++)
            {
                int localLength = 0;
                for (int j = 0; j < matrix[i].Length; j++)
                {
                    if (matrix[i][j] > 0)
                        localLength = i + 1;
                }
                if (localLength > length)
                    length = localLength;
            }
            return length;
        }


        public void printFigura()
        {
            for (int i = 0; i < matrix.Length; i++)
            {
                for (int j = 0; j < matrix[i].ToArray().Length; j++)
                    if (matrix[i][j] > 0)
                        Console.Write("o");
                    else
                    {
                        Console.Write(" ");
                    }
                Console.Write("\n");
            }

        }

        public void flipv()
        {
            for (int i = 0; i < matrix.Length; i++)
            {
                List<int> tempList = new List<int>();
                for (int j = matrix[i].Length - 1; j >= 0; j--)
                {
                    tempList.Add(matrix[i][j]);
                }
                for (int j = 0; j < tempList.ToArray().Length; j++)
                {
                    matrix[i][j] = tempList[j];
                }

            }
            this.clean();
        }

        public void fliph()
        {
            int[][] matrixtemp = new int[matrix.Length][];
            for (int i = matrix.Length - 1; i >= 0; i--)
            {

                matrixtemp[matrix.Length - 1 - i] = matrix[i];
            }
            matrix = matrixtemp;
            this.clean();
        }

        public void rotate90()
        {
            int[][] matrixtemp = new int[5][];
            for (int i = 0; i < matrixtemp.Length; i++)
            {
                matrixtemp[i] = new int[5];
            }
            for (int i = 0; i < matrix.Length; i++)
            {
                for (int j = 0; j < matrix[i].Length; j++)
                {
                    matrixtemp[j][i] = matrix[i][j];
                }
            }
            matrix = matrixtemp;
            this.fliph();
            this.clean();

        }

        public void clean()
        {
            bool cleaned = false;
            int i = 0;
            for (int j = 0; j < matrix[0].Length; j++)
                i += matrix[0][j];
            int[][] tempmatrix;
            if (i == 0)
            {
                cleaned = true;
                tempmatrix = new int[matrix.Length - 1][];
                for (int j = 1; j < matrix.Length; j++)
                {
                    tempmatrix[j - 1] = matrix[j];
                }
                matrix = tempmatrix;
            }

            i = 0;
            for (int j = 0; j < matrix.Length; j++)
                i += matrix[j][0];
            if (i == 0)
            {
                cleaned = true;
                tempmatrix = new int[matrix.Length][];
                for (int j = 0; j < matrix.Length; j++)
                {
                    tempmatrix[j] = new int[4];
                    for (int k = 1; k < matrix[j].Length; k++)
                    {
                        tempmatrix[j][k - 1] = matrix[j][k];
                    }

                }
                matrix = tempmatrix;
            }
            if (cleaned)
                this.clean();
        }
    }

    class coordenadas
    {
        int x;
        int y;

        public int GetX()
        {
            return x;
        }

        public int GetY()
        {
            return y;
        }

        public void SetX(int x)
        {
            this.x = x;
        }

        public void SetY(int y)
        {
            this.y = y;
        }


    }
}
